<template>
	<div>
		<Modal v-model="modal"
		       class="modal-full"
		       :title="actionModel.name"
		       width="90%">
			<div v-if="modalShow">
				<grid-panel :data="listData"
				            ref="list"
				            v-if="loadedData && loadedModel"
				            :model="listModel"
				            :hasCheck="true"></grid-panel>
			</div>
			<div slot="footer"
			     class="button-panel-button">
				<i-button @click="close">返回</i-button>
				<i-button v-if="hasSubmit"
				          @click="actionSubmit"
				          :disabled="!enableSubmit"
				          type="primary">确认</i-button>
			</div>
		</Modal>

	</div>
</template> 

<script>
import Base from '../listView/modal';
import $ from '@/common';
import GridPanel from '@/components/gridTableEditor/index';
import { billParser } from '@/common/parser';

export default {
	extends: Base,
	data() {
		return {
			hasSubmit: true,
			loadedData: false,
			loadedModel: false,
		};
	},
	created() {},
	methods: {
		load() {
			this.loadedData = false;
			this.loadedModel = false;
			var listPath = $.composePath(this.actionModel.param.path_data, this.$parent.actionData);
			var modelPath = $.composePath(this.actionModel.param.path_model, this.$parent.actionData);
			$.link(modelPath, null, {
				method: 'get',
				param: this.actionData,
			}).then(({ data }) => {
				this.listModel = billParser(data);
				this.loadedModel = true;
			});
			$.link(listPath, null, {
				param: this.actionData,
			}).then(res => {
				let data = res.data;
				if (data.data) data = data.data;
				this.listedData = data;
				this.loadedData = true;
			});
		},
		actionSubmit() {
			$.link(this.actionModel.param.path_submit, this.$refs.list.listData, {
				param: this.actionData,
			}).then(() => {
				this.close();
				this.$parent.actionSuccess();
				this.$owner.update();
			});
		},
	},
	components: {
		GridPanel,
	},
};
</script>
